import socket
from utils import SocketCommunication
import numpy as np
import sys
import pickle
import time
import pandas as pd
import struct
from io import BytesIO
tools = SocketCommunication()
sys.path.append(".")
SERVER_IP = "localhost"
RECV_PORT = 19900
data_name_list = ["input","Conv2d_1a_3x3", "Conv2d_2a_3x3", "Conv2d_2b_3x3",
                   "MaxPool_3a_3x3", "Conv2d_3b_1x1", "Conv2d_4a_3x3",
                   "MaxPool_5a_3x3", "Mixed_5b", "Mixed_5c",
                   "Mixed_5d", "Mixed_6a", "Mixed_6b", "Mixed_6c",
                   "Mixed_6d", "Mixed_6e", "Mixed_7a",
                   "Mixed_7b", "Mixed_7c"]
def send_msg():
    time_cost = []
    data_size = []
    for i in range(5):
        for data_name in ["input"]:#data_name_list:
            #i = i%3
            #client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            #client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            #client.settimeout(0.01)
            #client.connect((SERVER_IP, RECV_PORT))
            data = np.load("data/"+data_name+"_guitar.npy")
            #print("data shape",data.shape)
            a = time.time()
            #request = pickle.dumps(data)
            f = BytesIO()
            b = time.time()
            #np.save(f,data)
            #c = time.time()
            np.savez_compressed(f, frame=data)
            d = time.time()
            print(b - a, d - b)
            #f.seek(0)
            #request = f.read()
            #e = time.time()
            #request = np.load(BytesIO(request))['frame']
            #g = time.time()
            #request = pickle.loads(f)
            #l = time.time()
            #request = np.load(BytesIO(request))['frame']
            #g = time.time()
            #print(b-a,c-b,d-c)
            '''
            time_cost.append(round(b-a,3))
            data_size.append(len(request))
            #tools.send_data_bytes(client,request)
            
          
            '''
            #print("send data",len(request))
            #time.sleep(0.5)
    result_pd = pd.DataFrame({"time(s)":time_cost,"size(bytes)":data_size})
    """
    result_pd.to_excel("save_based_send.xlsx")
    """
send_msg()